﻿namespace TestTool.Tests.Common.NotificationConsumer
{
    using System;
    using TestTool.Proxies.Event;
    using TestTool.Tests.Common.Soap;

    public class NotificationConsumer : HttpSoapServer
    {
        private byte[] _rawData;
        public Action<SoapMessage<Notify>> OnNotify;

        public NotificationConsumer(string address) : base(address)
        {
        }

        protected override void OnMessageReceived(byte[] data)
        {
            try
            {
                this._rawData = data;
                SoapMessage<Notify> message = SoapBuilder.ParseMessage<Notify>(data, null);
                if (this.OnNotify != null)
                {
                    this.OnNotify(message);
                }
            }
            catch (Exception exception)
            {
                if (base.OnError != null)
                {
                    base.OnError(exception);
                }
            }
        }

        public byte[] RawData
        {
            get
            {
                return this._rawData;
            }
        }
    }
}

